package com.example.administrator.pandanotes;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by 于博 on 2018-07-13.
 *书籍列表适配器
 */
public class BooksAdapter extends ArrayAdapter {
    private final int resourceId;
    public BooksAdapter(Context context, int textViewResourceId, List<Books> objects)
    {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Books books = (Books) getItem(position);//获得当前项的books实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);//实例化一个view对象
        ImageView bookimage = (ImageView) view.findViewById(R.id.fruit_image);          //获取布局图片视图
        TextView booktext = (TextView) view.findViewById(R.id.fruit_name);              //获取布局书名视图
        bookimage.setImageResource(books.getBook_imageId());//为图片视图设置图片资源
        booktext.setText(books.getBook_name());//为文本视图设置文本内容
        return view;
    }
}
